//
//  VCShowPlay.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/8.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VCShowPlay: VCBase {
    
    private lazy var showPlayView:ShowPlayView = {
        let ui = ShowPlayView()
        ui.frame = CGRect(x: 0, y: realHeight, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - realHeight)
        return ui
    }()
    
    // 查询数据
    public var requestDict = NSDictionary()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        init_view()
        init_date()
    }
}

extension VCShowPlay {
    
    private func init_date() -> Void {
        self.doPost(api: "search/play", dict: requestDict) { (dict) in
            if self.isServerSuccess(dict: dict) != 1200 {
                self.noDataView.resetTipText = "未搜到相应航班,请重新选择"
                self.view.addSubview(self.noDataView)
                return
            }
            // 解析数据
            let arrs = dict.value(forKey: SP_BODYREQUEST) as! NSArray
            // 转化数据
            var temp = [PlayInfo]()
            for item in arrs {
                let info = PlayInfo(dict: item as! [String : String])
                temp.append(info)
            }
            self.showPlayView.playInfos = temp
        }
    }
    
    private func init_view() -> Void {
        view.addSubview(backroundWhite)
        view.addSubview(showPlayView)
    }
}
